#include "quaternion.h"
#include "ui_quaternion.h"

quaternion::quaternion(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::quaternion)
{
    ui->setupUi(this);
}

quaternion::~quaternion()
{
    delete ui;
}
void quaternion::setDag(DAG* dag){
    this->dag = dag;
}
void quaternion::addItem(QString op,QString op1,QString op2,QString re){
    int n = ui->tableWidget->rowCount();
    ui->tableWidget->insertRow(n);
    QTableWidgetItem* item0 = new QTableWidgetItem(QString::number(n));
    QTableWidgetItem* item1 = new QTableWidgetItem(op);
    QTableWidgetItem* item2 = new QTableWidgetItem(op1);
    QTableWidgetItem* item3 = new QTableWidgetItem(op2);
    QTableWidgetItem* item4 = new QTableWidgetItem(re);
    item0->setTextAlignment(Qt::AlignCenter);
    item1->setTextAlignment(Qt::AlignCenter);
    item2->setTextAlignment(Qt::AlignCenter);
    item3->setTextAlignment(Qt::AlignCenter);
    item4->setTextAlignment(Qt::AlignCenter);
    ui->tableWidget->setItem(n,0,item0);
    ui->tableWidget->setItem(n,1,item1);
    ui->tableWidget->setItem(n,2,item2);
    ui->tableWidget->setItem(n,3,item3);
    ui->tableWidget->setItem(n,4,item4);
}
void quaternion::showOptimize(){
    //this->ui->tableWidget->setRowCount(dag->news.size());
    QString op,arg1,arg2,result;
    for(int i = 0;i<dag->news.size();i++){
        op = QString::fromStdString(dag->news[i].op);
        arg1 = QString::fromStdString(dag->news[i].arg1);
        arg2 = QString::fromStdString(dag->news[i].arg2);
        result = QString::fromStdString(dag->news[i].result);
        addItem(op,arg1,arg2,result);
    }
}
void quaternion::showQuaternary(){
    QString op,arg1,arg2,result;
    for(int i = 0;i<dag->olds.size();i++){
        op = QString::fromStdString(dag->olds[i].op);
        arg1 = QString::fromStdString(dag->olds[i].arg1);
        arg2 = QString::fromStdString(dag->olds[i].arg2);
        result = QString::fromStdString(dag->olds[i].result);
        addItem(op,arg1,arg2,result);
    }
}

